<template>
	<view>
		<!-- 头部 -->
		<view class="navbar">
			<u-icon @click="navigateBack" class="icon-left" name="arrow-left" color="#000" size="50"></u-icon>
			<text>邀请管理员</text>
		</view>
		<!-- 内容 -->
		<view class="section">
			<!-- <text>被邀请人姓名：</text>
			<input type="text" value="" placeholder="请输入手机号" /> -->
			<text>被邀请人手机号：</text>
			<input type="text" value="" v-model="phone" placeholder="请输入手机号" />
			<view class="binding" @click='invite'><text>确认并邀请</text></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: '',
				deviceno:''
			}
		},
		mounted(){
			this.$api.getDeviceList().then(res=>{
				let list = []
				if(res.code===200){
					list = res.result.list
					list.forEach(ele=>{
						if(ele.deviceStatus==='Y'){
							this.deviceno = ele.code
						}
					})
				}
			})
		},
		methods: {
			async invite() {
				if (this.phone.length === 11) {
					let tpl_param = {
						phone: this.phone,
						deviceno:this.deviceno
					};
					uni.showLoading({
						title: '加载中',
						mask: true
					});
					let res = await this.$api.inviteJoin(tpl_param);

					if (res.code === 200) {
					uni.showModal({
						title: '邀请绑定',
						content: '邀请绑定成功'
					});
						// uni.navigateBack({
						// 	url:'../adminstrators'
						// })
						
					} else {
						uni.showModal({
							title: '邀请绑定',
							content: res.message,
							showCancel: false
						});

					}
					uni.hideLoading();

				} else {
					uni.showModal({
						content: '请输入正确手机号'
					});
				}
			},
			navigateBack() {
				uni.navigateTo({
					url: '../administrators'
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	// 头部
	.navbar {
		padding-top: 90rpx;
		padding-bottom: 40rpx;
		width: 750rpx;
		color: #000;
		background-color: #fff;
	}

	.navbar>text {
		font-size: 36rpx;
		padding-left: 200rpx;
		font-weight: bold;
	}

	// 内容
	// 内容
	.section {
		padding: 30rpx;
	}

	.section>text {
		font-size: 32rpx;
		font-weight: bold;
	}

	.section>input {
		padding: 30rpx;
		padding-left: 50rpx;
		background-color: rgb(246, 247, 251);
		border-radius: 50rpx;
		margin-top: 30rpx;
		margin-bottom: 80rpx;
	}

	.binding {
		box-shadow: 1px 1px 2px rgb(228, 227, 227), 0 0 5px rgb(228, 227, 227), 0 0 1px rgb(228, 227, 227);
		border-radius: 50rpx;
		text-align: center;
		margin-bottom: 35rpx;
		padding: 20rpx;
		font-size: 36rpx;
		background-color: rgb(68, 92, 223);
		color: #fff;
		margin-top: 200rpx;
	}
</style>
